function pushbutton1_Callback(hObject, eventdata, handles)  
global T_new_with_headers2  T_new_with_headers4 T_new_with_headers6
    % 假设 handles.sheet_data 已经包含了从Excel读取的数据（包括标题行）  
    T = handles.sheet_data;  
      
    % 检查是否包含标题行  
    if isempty(T) || size(T, 1) < 2  
        error('数据不包含足够的行来作为标题！');  
    end  
      
    % 提取原数据的标题行作为列名  
    originalColumnNames = T(1, :);  
    originalColumnNames2 = T(2, :); 
    % 移除原数据的第一行（标题行）  
    T = T(3:end, :);  
  
      
    % 初始化风险评分数组  
    riskScores = 0 * ones(size(T, 1), 1); 
    %投运前评估情况
%例行试验检测
       for i = 1:size(T, 1)  
        if strcmp(T{i, 4}, '合格')  
            riskScores(i) = riskScores(i) - 2;  
        end  
        
       end  
    for i = 1:size(T, 1)  
        if strcmp(T{i, 4}, '一般缺陷')  
            riskScores(i) = riskScores(i) + 1.27;  
        end  
        
    end   
    for i = 1:size(T, 1)  
        if strcmp(T{i, 4}, '严重缺陷') ||   strcmp(T{i, 4}, '严重缺陷以上') ||   strcmp(T{i, 4}, '严重缺陷及以上')
            riskScores(i) = riskScores(i) + 1.71;   
        end  
    end   
    %近三年本体故障次数
    for i = 1:size(T, 1)  
        if T{i, 8} == 1
            riskScores(i) = riskScores(i) + 2.4;  
        end  
        
    end   
        %近三年接头故障次数
    for i = 1:size(T, 1)  
        if T{i, 9} == 1
            riskScores(i) = riskScores(i) + 2.4;  
        end  
        
    end   
%通道环境
 for i = 1:size(T, 1)  
        if strcmp(T{i, 12}, '优')  
            riskScores(i) = riskScores(i) + 0;  
        end  
        
 end  
       for i = 1:size(T, 1)  
        if strcmp(T{i, 12}, '良')  || strcmp(T{i, 12}, '良好')
            riskScores(i) = riskScores(i) + 0;  
        end  
        
       end  
    for i = 1:size(T, 1)  
        if strcmp(T{i, 12}, '一般')  
            riskScores(i) = riskScores(i) + 1.87;  
        end  
        
    end   
    for i = 1:size(T, 1)  
        if strcmp(T{i, 12}, '差')  
            riskScores(i) = riskScores(i) + 2.1;  
        end  
        
    end   
   
    %井内电缆数量
      for i = 1:size(T, 1)  

        if T{i, 13} == 1
        riskScores(i) = riskScores(i) + 1.67;  

        end  
       end  

    for i = 1:size(T, 1)  
       if T{i, 13} == 2  
        riskScores(i) = riskScores(i) + 2.01;
       end  
    end  

    for i = 1:size(T, 1)  
         if T{i, 13} == 3 
        riskScores(i) = riskScores(i) + 1.4; 

         end  
    end  

    for i = 1:size(T, 1)   
         if T{i, 13} == 5 
        riskScores(i) = riskScores(i) + 1.63; 
         end  
    end  

    for i = 1:size(T, 1)  
        if T{i, 13} == 6  
        riskScores(i) = riskScores(i) + 1.78;  
        end  
    end  

    for i = 1:size(T, 1)  
        if T{i, 13} == 8  
        riskScores(i) = riskScores(i) + 2.01;  
        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 13} == 9  
        riskScores(i) = riskScores(i) + 2.01;  
        end  
    end  


    %低压线路共通道
    for i = 1:size(T, 1)  
        if T{i, 14} == 1  
        riskScores(i) = riskScores(i) + 2.01;
        end  
    end  

    %电缆头制作人员
     for i = 1:size(T, 1)
         if T{i, 16} == 0.01
        riskScores(i) = riskScores(i) - 2;  
        end  
     end  
     for i = 1:size(T, 1)
         if T{i, 16} == 0.12
        riskScores(i) = riskScores(i) - 1;  
        end  
     end  
          for i = 1:size(T, 1)
         if T{i, 16} == 0.13
        riskScores(i) = riskScores(i) - 1;  
        end  
          end  
 for i = 1:size(T, 1)
         if T{i, 16} >= 0 && T{i, 16} <= 0.03
        riskScores(i) = riskScores(i) + 0;  
        end  
 end  
 for i = 1:size(T, 1)
         if T{i, 16} > 0.03 && T{i, 16} <= 0.1
        riskScores(i) = riskScores(i) + 2.01;  
        end  
 end   
 for i = 1:size(T, 1)
         if T{i, 16} > 0.1 && T{i, 16} <= 0.15
        riskScores(i) = riskScores(i) + 3.5;  
        end  
 end   
 for i = 1:size(T, 1)
         if T{i, 16} > 0.15
        riskScores(i) = riskScores(i) + 2.01;  
        end  
 end  
 %施工环境

%电缆井数量
 for i = 1:size(T, 1)
         if T{i, 11} == 6
        riskScores(i) = riskScores(i) - 1.45;  
        end  
 end  
  for i = 1:size(T, 1)
         if T{i, 11} == 7
        riskScores(i) = riskScores(i) - 1.45;  
        end  
  end  
   for i = 1:size(T, 1)
         if T{i, 11} == 8
        riskScores(i) = riskScores(i) - 1.45;  
        end  
   end  
   for i = 1:size(T, 1)
         if T{i, 11} == 15
        riskScores(i) = riskScores(i) - 1.45;  
        end  
   end  
      for i = 1:size(T, 1)
         if T{i, 11} == 16
        riskScores(i) = riskScores(i) - 1.45;  
        end  
      end  
   for i = 1:size(T, 1)
         if T{i, 11} == 18
        riskScores(i) = riskScores(i) - 1.45;  
        end  
   end  
     for i = 1:size(T, 1)
         if T{i, 11} >= 5&& T{i, 11} < 10
        riskScores(i) = riskScores(i) + 1.45;  
        end  
    end  
 for i = 1:size(T, 1)
         if T{i, 11} >=10  && T{i, 11} <= 15
        riskScores(i) = riskScores(i) + 6.58;  
        end  
 end   
 for i = 1:size(T, 1)
         if T{i, 11} > 15 && T{i, 11} <= 20
        riskScores(i) = riskScores(i) + 4.03;  
        end  
 end   
  for i = 1:size(T, 1)
         if T{i, 11} > 20 && T{i, 11} <= 25
        riskScores(i) = riskScores(i) + 6.03;  
        end  
  end   
  for i = 1:size(T, 1)
         if T{i, 11} > 25 && T{i, 11} <= 30
        riskScores(i) = riskScores(i) + 6.03;  
        end  
 end   
 for i = 1:size(T, 1)
         if T{i, 11} > 35
        riskScores(i) = riskScores(i) + 8;  
        end  
 end  

    %电缆头投运时间
    for i = 1:size(T, 1)
         if T{i, 18} == 2
        riskScores(i) = riskScores(i) - 1;  
        end  
    end 
        for i = 1:size(T, 1)
         if T{i, 18} == 4
        riskScores(i) = riskScores(i) - 1;  
        end  
        end
            for i = 1:size(T, 1)
         if T{i, 18} == 6
        riskScores(i) = riskScores(i) - 1;  
        end  
            end
    for i = 1:size(T, 1)
         if T{i, 18} == 7
        riskScores(i) = riskScores(i) - 1;  
        end  
    end
        for i = 1:size(T, 1)
         if T{i, 18} == 8
        riskScores(i) = riskScores(i) - 1;  
        end  
        end

     for i = 1:size(T, 1)
         if T{i, 18} >= 0 && T{i, 18} < 3
        riskScores(i) = riskScores(i) + 2.01;  
        end  
    end  
 for i = 1:size(T, 1)
         if T{i, 18} >= 3 && T{i, 18} <= 5
        riskScores(i) = riskScores(i) + 2.01;  
        end  
 end   
 for i = 1:size(T, 1)
         if T{i, 18} > 5 && T{i, 18} < 10
        riskScores(i) = riskScores(i) + 2.14;  
        end  
 end   
 for i = 1:size(T, 1)
         if T{i, 18} >= 10
        riskScores(i) = riskScores(i) + 3.56;  
        end  
 end  
 %交接试验检测情况
   for i = 1:size(T, 1)  
        if strcmp(T{i, 19}, '优')  
            riskScores(i) = riskScores(i) + 0;  
        end  
        
  end   
    for i = 1:size(T, 1)  
        if strcmp(T{i, 19}, '良')  
            riskScores(i) = riskScores(i) + 0;  
        end  
        
    end   
    for i = 1:size(T, 1)  
        if strcmp(T{i, 19}, '合格')  || strcmp(T{i, 19}, '一般')|| strcmp(T{i, 19}, '一般缺陷')
            riskScores(i) = riskScores(i) + 1.83;  
        end  
        
    end  

    for i = 1:size(T, 1)  
        if strcmp(T{i, 19}, '严重缺陷')  || strcmp(T{i, 19}, '严重缺陷以上')||strcmp(T{i, 19}, '严重缺陷及以上')
            riskScores(i) = riskScores(i) + 2.5;  
        end  
        
    end   

    %年平均负载率
 for i = 1:size(T, 1)  
        if T{i, 5} > 0.4 &&  T{i, 5} <= 0.5
        riskScores(i) = riskScores(i) + 2; 

        end  
 end   
    for i = 1:size(T, 1)  
        if T{i, 5} > 0.5 &&  T{i, 5} <= 0.6
        riskScores(i) = riskScores(i) + 1.66; 

        end    
    end  
    for i = 1:size(T, 1)  
        if T{i, 5} > 0.6 &&  T{i, 5} <= 0.7
        riskScores(i) = riskScores(i) + 6.38; 

        end    
    end  

%年最大负载率
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.1 &&  T{i, 6} <= 0.2
        riskScores(i) = riskScores(i) - 2; 

        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.2 &&  T{i, 6} <= 0.3
        riskScores(i) = riskScores(i) - 2; 

        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.4 &&  T{i, 6} <= 0.5
        riskScores(i) = riskScores(i) - 1.5; 

        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.5 &&  T{i, 6} <= 0.6
        riskScores(i) = riskScores(i) - 1.3; 

        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.6 &&  T{i, 6} <= 0.7
        riskScores(i) = riskScores(i) - 1; 

        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.7 &&  T{i, 6} <= 0.8
        riskScores(i) = riskScores(i) - 1; 

        end  
    end  
    for i = 1:size(T, 1)  
        if T{i, 6} > 0.3 &&  T{i, 6} <= 0.4
        riskScores(i) = riskScores(i) + 1.71; 

        end  
    end  
    for i = 1:size(T, 1)  
         if T{i, 6} > 0.8 &&  T{i, 6} <= 0.9
        riskScores(i) = riskScores(i) + 1.6; 

        end  
    end  

    %运行年限
    for i = 1:size(T, 1)  
         if T{i, 7} == 2
        riskScores(i) = riskScores(i) - 1.5;  
        end   
    end  
     for i = 1:size(T, 1)  
         if T{i, 7} == 9
        riskScores(i) = riskScores(i) - 2;  
        end   
     end  
     for i = 1:size(T, 1)  
         if T{i, 7} == 11
        riskScores(i) = riskScores(i) - 1.5;  
        end   
     end  
     for i = 1:size(T, 1)  
         if T{i, 7} == 12
        riskScores(i) = riskScores(i) - 2;  
        end   
     end  
    for i = 1:size(T, 1)  
         if T{i, 7} == 18
        riskScores(i) = riskScores(i) - 2;  
        end   
    end  

     for i = 1:size(T, 1)  
         if T{i, 7} <= 3  
        riskScores(i) = riskScores(i) + 0;  
        end   
    end  
     for i = 1:size(T, 1)  
         if T{i, 7} > 3 &&   T{i, 7} <= 8
        riskScores(i) = riskScores(i) + 3.3;  
         end   
     end  
      for i = 1:size(T, 1)  
         if T{i, 7} > 8 &&   T{i, 7} <= 15
        riskScores(i) = riskScores(i) + 4.3;  
         end   
     end  
    for i = 1:size(T, 1)  
        if T{i, 7} > 15   
        riskScores(i) = riskScores(i) + 1.55;  
        end   
    end
    for i=  1:size(T, 1)
        if riskScores(i) < 0
            riskScores(i) = 0 ;
        end
    end
    
     riskScoresCell1 = arrayfun(@(x) num2str(round(x * 100) / 100, '%.2f'), riskScores, 'UniformOutput', false);
     riskScoresCell2 = num2cell(riskScores)
%      riskScoresCell2 = arrayfun(@(x) round(x * 100) / 100, riskScores, 'UniformOutput', false);




    T_new1 = [T, riskScoresCell1];  
    T_new2 = [T, riskScoresCell2];  


      
    % 添加新的列名 "风险评分" 到原列名数组中  
    newColumnNames = [originalColumnNames2, {'风险评分'}]; 
    newColumnNames2 = [originalColumnNames, {''}];
      
    % 更新 handles 中的 columnNames（尽管这里可能不再需要，因为我们已经直接在 uitable 中设置了列名）  
    % 但为了保持一致性，还是更新它  
    handles.columnNames = newColumnNames;  
    handles.columnNames2 = newColumnNames2; 
    guidata(hObject, handles);  
      
    % 将新的列名作为第一行添加到数据中，并设置到 uitable 中  
    % 注意：这里我们将列名和数据一起放入了 T_new_with_headers 中  
    T_new_with_headers1 = [newColumnNames2; T_new1];  
    T_new_with_headers2 = [newColumnNames; T_new_with_headers1];
    T_new_with_headers3 = [newColumnNames; T_new2];  
    T_new_with_headers4 = [newColumnNames2; T_new_with_headers3];
    set(handles.uitable1, 'Data', T_new_with_headers2);
    
    T2 = T_new_with_headers4;  
    T3 = T_new_with_headers2;

    originalColumnNames1 = T2(1, :);  
    originalColumnNames2 = T2(2, :);

      
    % 移除原数据的第一行（标题行）  
    T2 = T2(3:end, :);  
    T3 = T3(3:end, :); 
      
    % 初始化风险评分数组  
    riskGrade = cell(size(T2, 1), 1);  
    for i = 1:size(T2, 1)  
        if  riskScores(i) >= 17  
            riskGrade{i} = '高风险';  
        elseif  riskScores(i) >= 10 && riskScores(i) < 17
            riskGrade{i} = '中风险';
        elseif riskScores(i) < 10
            riskGrade{i} = '低风险';
        end  
        
    end  
      
    % 将原数据和风险评分数组合并成新的元胞数组  
    T2_new = [T3, riskGrade];  
    T2_new1 = [T2, riskGrade];
    
      
    % 添加新的列名 "风险评分" 到原列名数组中  
    newColumnNames1 = [originalColumnNames2, {'风险等级'}];  
    newColumnNames2 = [originalColumnNames1, {''}];
      
    % 更新 handles 中的 columnNames（尽管这里可能不再需要，因为我们已经直接在 uitable 中设置了列名）  
    % 但为了保持一致性，还是更新它  
    
    handles.columnNames = newColumnNames1;  
    handles.columnNames2 = newColumnNames2; 
    guidata(hObject, handles); 
      
    % 将新的列名作为第一行添加到数据中，并设置到 uitable 中  
    % 注意：这里我们将列名和数据一起放入了 T_new_with_headers 中  
    
    T_new_with_headers11 = [newColumnNames1; T2_new];  
    T_new_with_headers2 = [newColumnNames2; T_new_with_headers11];
    T_new_with_headers5 = [newColumnNames1; T2_new1];  
    T_new_with_headers6 = [newColumnNames2; T_new_with_headers5];
    set(handles.uitable1, 'Data', T_new_with_headers2);
     % 弹窗部分 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
    global Size3
    Size3=size(T_new_with_headers6)
        resultData1 = cell(0,5); % 初始化一个空的cell数组 
        Y1 = 1;
        Y = T_new_with_headers6{3,1};
        Fy1 = 1;
%         Fy2 = 0;
        Fy = 0;
%         disp(['T_new_with_headers2{i,20}的数据类型是：', class(T_new_with_headers2{i,20})]);
for i = 3:Size3(1)
        if T_new_with_headers6{i,1} == Y
           Fy1 = Fy1*(100-T_new_with_headers6{i,20})/100;
%            Fy2 = Fy2+T_new_with_headers6{i,20};
        else
           resultData1{Y1,1} = T_new_with_headers6{i-1,1};
           resultData1{Y1,2} = T_new_with_headers6{i-1,2};
           resultData1{Y1,3} = T_new_with_headers6{i-1,3};
           Fy = (1 - Fy1)*100;
           resultData1{Y1,4} = Fy;
           Y1 = Y1+1;
           Y = T_new_with_headers6{i,1};
           Fy1 = 1;
%            Fy2 = 0;
           Fy1 = Fy1*(100-T_new_with_headers6{i,20})/100;
%            Fy2 = Fy2+T_new_with_headers6{i,20};
           Fy = 0;
         end   
end 

           resultData1{Y1,1} = T_new_with_headers6{Size3(1),1};
           resultData1{Y1,2} = T_new_with_headers6{Size3(1),2};
           resultData1{Y1,3} = T_new_with_headers6{Size3(1),3};
           Fy = (1 - Fy1)*100;
           resultData1{Y1,4} = Fy;
 Size4 = size(resultData1)
 
 for i = 1:Size4(1)
     if resultData1{i,4} >= 43.73  
        resultData1{i,5} = '高风险';
     elseif resultData1{i,4} >= 20 &&  resultData1{i,4} < 43.73
        resultData1{i,5} = '中风险';
     elseif resultData1{i,4} < 20
        resultData1{i,5} = '低风险';
     end
 end
if size(resultData1, 2) >= 4  
    % 对第四列的每个元素进行格式化，只显示两位小数  
    % 注意：由于resultData1(:, 4)是cell数组的一列，我们需要使用{}来索引单个元素  
    % 因此，我们使用cell2mat来将这一列转换为double数组，但在这里我们可以直接使用cellfun来避免转换  
    formattedCol = cellfun(@(x) num2str(x, '%.2f'), resultData1(:, 4), 'UniformOutput', false);  
      
    % 现在，将格式化后的第四列替换回原cell数组  
    % 注意：MATLAB不允许直接替换cell数组中的列，但我们可以创建一个新的cell数组  
    newCellArray = cell(size(resultData1)); % 创建一个与resultData1相同大小的新cell数组  
    newCellArray(:, 1:3) = resultData1(:, 1:3); % 复制前三列  
    newCellArray(:, 4) = formattedCol; % 替换第四列为格式化后的字符串  
    newCellArray(:, 5) = resultData1(:, 5); % 复制第五列 
end

% 将表头添加到resultData1的第一行  
if ~isempty(newCellArray)  
    % 如果 resultData1 非空，将表头（前两行）添加到其前面  
    resultData1 = [T_new_with_headers6(1:2, [1,2,3,20,21]); newCellArray]; 
end  
    % 根据结果数据创建新的表格弹窗  
    if ~isempty(newCellArray)  
        % 创建一个新的Figure
        fig = figure('Name', '电缆段风险评估结果', 'NumberTitle', 'off', 'MenuBar', 'none','Position', [600, 160, 450, 600], 'Resize', 'off');  
        % 创建uitable并设置数据  
        cols = string(arrayfun(@(x) sprintf('列%d', x), 1:size(resultData1, 2), 'UniformOutput', false)); % 自动生成列名  
        uitable_handle = uitable(fig, 'Data', resultData1, 'ColumnName', cols, ...  
            'RowName', arrayfun(@(x) sprintf('行%d', x), 1:size(resultData1, 1), 'UniformOutput', false), ...  
            'Position', [10,10,980,580]); % 调整Position以适应你的需求
    end
